"use strict";

import { promise } from "@xmpp/events";
import TlsSocket from "@xmpp/tls/src/main/lib/Socket";
import {Socket as TcpSocket} from "@xmpp/connection_tcp/src/main/connection-tcp/lib/net"
function canUpgrade(socket) {
    return socket instanceof TcpSocket && !(socket instanceof TlsSocket)
}

async function upgrade(service) {
  const tlsSocket = new TlsSocket();
        tlsSocket.connect(service);
  await promise(tlsSocket, "connect");
  return tlsSocket ;
}

export { canUpgrade, upgrade };
